<?php

/**
 * statistika actions.
 *
 * @package    dnevnik
 * @subpackage statistika
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 12479 2008-10-31 10:54:40Z fabien $
 */
class statistikaActions extends sfActions
{
 /**
  * Executes index action
  *
  * @param sfRequest $request A request object
  */
  public function executeSms(sfWebRequest $request)
  {
     $skolas = $this->getSkolas();
     $skolas_2 = $skolas;
     unset($skolas_2['']);

     if($this->getRequest()->isMethod('post'))
     {
        $skola_id = $request->getParameter('skola_id');
        if($skola_id != '')
          $statistike = new Statistike(array($skola_id => $skolas[$skola_id]));
        else $statistike = new Statistike($skolas_2);
        $this->sms_logs = $statistike->smsLog($request->getParameter('godina'), $request->getParameter('mesec'));
     }
     else
     {
        $statistike = new Statistike($skolas_2);
        $this->sms_logs = $statistike->smsLog(date('Y'), date('n'));
     }

     $i = 0;
     $mesecs = array();
     while($i++ < 12)
       $mesecs[$i] = $i;
     $tr_god = date('Y');
     $i = 2008;
     while($i++ < $tr_god)
       $godinas[$i] = $i;

     $this->skolas = $skolas;
     $this->godinas = $godinas;
     $this->mesecs = $mesecs;
  }

  public function executeSmsDan(sfWebRequest $request)
  {
     $skolas = $this->getSkolas();
     $skola_id = $request->getParameter('skola_id');
     if($skola_id != '')
       $statistike = new Statistike(array($skola_id => $skolas[$skola_id]));
     else
     {
        $statistike = new Statistike($skolas);
     }
     $this->sms_logs = $statistike->smsLog($request->getParameter('godina'), $request->getParameter('mesec'), $request->getParameter('dan'));
  }

  public function executeUplata(sfWebRequest $request)
  {
     $skolas = $this->getSkolas();
     $skolas_2 = $skolas;
     unset($skolas_2['']);

     if($this->getRequest()->isMethod('post'))
     {
        $skola_id = $request->getParameter('skola_id');
        if($skola_id != '')
          $statistike = new Statistike(array($skola_id => $skolas[$skola_id]));
        else $statistike = new Statistike($skolas_2);
        $this->uplatas = $statistike->uplata($request->getParameter('godina'), $request->getParameter('mesec'));
     }
     else
     {
        $statistike = new Statistike($skolas_2);
        $this->uplatas = $statistike->uplata(date('Y'), date('n'));
     }

     $i = 0;
     $mesecs = array();
     while($i++ < 12)
       $mesecs[$i] = $i;
     $tr_god = date('Y');
     $i = 2008;
     while($i++ < $tr_god)
       $godinas[$i] = $i;

     $this->skolas = $skolas;
     $this->godinas = $godinas;
     $this->mesecs = $mesecs;
  }

  public function executeUplataDan(sfWebRequest $request)
  {
     $skolas = $this->getSkolas();
     $skola_id = $request->getParameter('skola_id');
     if($skola_id != '')
       $statistike = new Statistike(array($skola_id => $skolas[$skola_id]));
     else
     {
        $statistike = new Statistike($skolas);
     }
     $this->uplatas = $statistike->uplata($request->getParameter('godina'), $request->getParameter('mesec'), $request->getParameter('dan'));
  }

  private function getSkolas()
  {
     $skolas = array('' => 'Izaberi');
     $skola_dbs = DbFinder::from('Skola')->select(array('Id', 'Ime'), sfModelFinder::SIMPLE)->find();
     foreach($skola_dbs as $skola_db)
     {
        list($skola_id, $ime) = $skola_db;
        $skolas[$skola_id] = $ime;
     }

     return $skolas;
  }
}
